/**

This file is part of MaCI/GIMnet.

MaCI/GIMnet is free software: you can redistribute it and/or modify it 
under the terms of the GNU Lesser General Public License as published 
by the Free Software Foundation, either version 3 of the License, or 
(at your option) any later version.

MaCI/GIMnet is distributed in the hope that it will be useful, but WITHOUT 
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 
FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public 
License for more details.

You should have received a copy of the GNU Lesser General Public 
License along with GIMnet. (See COPYING.LESSER) If not, see 
<http://www.gnu.org/licenses/>.

**/
/**
* Reads Log files Generated by MaCI Logger application
* 
**/
#ifndef _WIRELESSPOSITIONLOG_H_
#define _WIRELESSPOSITIONLOG_H_
#include <string>
#include <map>
#include "owndebug.h"
#include "ownutils.h"
#include "gimutils.h"
#include "WirelessServer.hpp"
#include "PositionServer.hpp"
#include "databacklog.hpp"

struct SignalStrengthWithPosition{
		uint32_t rss; ///< received signal strength value
		float x;
		float y;
 		std::string ESSID;
		SignalStrengthWithPosition(uint32_t r, float xx, float yy, std::string str):
		  rss(r),
			x(xx),
			y(yy),
			ESSID(str)				
		{
		
		}
};

class CWirelessPositionLog{
		public:
				CWirelessPositionLog(std::string wirelessLogFile, std::string positionLogFile);
				~CWirelessPositionLog();		
				
				/**
				* Returns essid based on MAC key
				*/
				std::string getESSID(uint64_t key);
				/**
				* Returns the number of measurements on one MAC key
				*/
				int getNumMeasurements(uint64_t key);
				
				///Container for all wireless measurements
				std::vector<MaCI::Wireless::CWirelessData *> wirelessData;
				//std::map<gim::time,MaCI::Wireless::CWirelessData *> wirelessData;
				///Container for all Position data
				std::map<gim::time,MaCI::Position::CPositionData *> positionData;
				/// Backlog
				gim::CDataBacklog<MaCI::Position::CPositionData> iPositionBacklog;
				
				std::list<gim::time> wTimes;
				std::list<gim::time> pTimes;
				
				std::multimap<uint64_t, SignalStrengthWithPosition> signalMap;
				std::vector<uint64_t> signalKeys;
				
		private:
				bool readWirelessFile(std::string wirelessLogFile);
				bool readPositionLogFile( std::string positionLogFile);
				bool createIDMap();
};



#endif
